/**
 * Created by zywy-022 on 2024/5/14.
 * */
#ifndef TINYXML_PARSERTCLCONFIG_H
#define TINYXML_PARSERTCLCONFIG_H

#include <string>
#include <vector>
#include "logger.h"

using std::string;
using std::vector;

enum class dds_net_proto_type {
    udp,
    tcp
};

enum class dds_recv_reliability_kind_type {
    BEST_EFFORT_RELIABILITY_QOS,
    RELIABLE_RELIABILITY_QOS
};

enum class dds_keep_history_policy_type {
    keep_all,
    keep_last
};

enum class dds_ownership_kind_type {
    shared,
    exclusive
};

class rtcl_dds_type {
public:
    int dp_send_heartbeat_interval = 3;
    int dp_break_connection_limit = 60;
    int dp_bind_metatraffic_addr = 1;
    int dp_bind_usertraffic_addr = 1;
    int disable_addr_sorting = 1;
    int disable_iface_state_checking = 1;
    int disable_in_proc_loopback = 1;
    int tcp_always_reconnect = 1;
//    int enable_msg_stat_info = 0;
//    int use_multicast = 0;
    string multicast_group = "230.231.232.233";
    int comm_port = 0;
    dds_net_proto_type net_proto = dds_net_proto_type::tcp;
    dds_recv_reliability_kind_type recv_reliability_kind = dds_recv_reliability_kind_type::BEST_EFFORT_RELIABILITY_QOS;
    dds_keep_history_policy_type keep_history_policy = dds_keep_history_policy_type::keep_all;
    int keep_history_depth = 128;
    dds_ownership_kind_type ownership_kind = dds_ownership_kind_type::shared;
    int ownership_strength = 4;
    int enable_zerocopy = 0;
    int receive_buf_len = 512;
//    int set_cpu_affinity = 0;
//    vector<int> send_cores;
//    vector<int> recv_cores;
    string dds_home = "";
};

/* 解析DDSConfig.xml文件 */
class ParseDDSConfig {
public:
    const char *Parse_RTCL_Config(const char *rtcl_fileName);

    const rtcl_dds_type &getRTCLDDSConfig();

    bool parseConfigFileSuccess();

private:
    void Parse_split(const string &str, vector<string> &tokens, const string delimiter = ",");

    void Parse_split(const string &str, vector<int> &tokens, const string delimiter = ",");

    rtcl_dds_type rtcl_dds;

    bool parseSuccess = false;
};


#endif //TINYXML_PARSERTCLCONFIG_H
